<template>
  <div class="Detail">
    <div class="mixin">
      <!-- 左侧边栏 -->
      <div class="sidebar">
        <div class="avatar-section">
          <div class="block">
            <el-avatar :size="50" :src="circleUrl"></el-avatar>
          </div>
          <div class="ip">192.168.1.132</div>
        </div>
        <div class="menu-list">
          <button 
            class="menu-item" 
            :class="{ active: currentRoute === '/PersonalCenter/MyCollection' }"
            @click="goToPage('/PersonalCenter/MyCollection')"
          >
            我的收藏
          </button>
          <button 
            class="menu-item" 
            :class="{ active: currentRoute === '/PersonalCenter/Mybrowsing' }"
            @click="goToPage('/PersonalCenter/Mybrowsing')"
          >
            我的浏览
          </button>
          <button 
            class="menu-item" 
            :class="{ active: currentRoute === '/PersonalCenter/Mysearch' }"
            @click="goToPage('/PersonalCenter/Mysearch')"
          >
            我的检索
          </button>
          <button 
            class="menu-item" 
            :class="{ active: currentRoute === '/PersonalCenter/MyDownloads' }"
            @click="goToPage('/PersonalCenter/MyDownloads')"
          >
            我的下载
          </button>
          <button 
            class="menu-item" 
            :class="{ active: currentRoute === '/PersonalCenter/MyFeedback' }"
            @click="goToPage('/PersonalCenter/MyFeedback')"
          >
            我的反馈
          </button>
             <button 
            class="menu-item" 
            :class="{ active: currentRoute === '/PersonalCenter/Myclaim' }"
            @click="goToPage('/PersonalCenter/Myclaim')"
          >
            我的认领
          </button>
          <button 
            class="menu-item" 
            :class="{ active: currentRoute === '/PersonalCenter/RecordOflncorrectWords' }"
            @click="goToPage('/PersonalCenter/RecordOflncorrectWords')"
          >
            错词记录
          </button>
        </div>
      </div>
      <div class="main-content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "PersonalCenter",
  data() {
    return {
      circleUrl: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
      currentRoute: "" // 存储当前路由路径，用于判断激活状态
    };
  },
  mounted() {
    // 页面初始化时，获取当前路由路径
    this.currentRoute = this.$route.path;
  },
  watch: {
    // 监听路由变化，实时更新currentRoute（确保切换路由后按钮高亮正确）
    $route(newRoute) {
      this.currentRoute = newRoute.path;
    }
  },
  methods: {
    // 跳转方法：接收路由路径，调用Vue Router跳转
    goToPage(path) {
      this.$router.push(path);
    }
  }
};
</script>

<style lang="scss" scoped>
/* 样式无需大幅修改，保留原样式即可 */
.Detail {
  padding-top: 24px;
  padding-bottom: 40px;
  display: flex;
  background: #f9faff;
  flex-direction: column;
  align-items: center;

  .mixin {
    width: 1400px;
    display: flex;
    gap: 20px;
  }

  .sidebar {
    width: 320px;
    height: 630px;
    background: #ffffff;
    box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.07);
    border-radius: 4px;
    padding: 42px 0px 20px 0px;
    box-sizing: border-box;

    .avatar-section {
      display: flex;
      flex-direction: column;
      align-items: center;
      padding-bottom: 29px;
      margin-bottom: 24px;
      border-bottom: 1px solid #e4e4e4;
      .ip {
        margin-top: 21px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        font-size: 22px;
        color: #333333;
      }
    }

    .menu-list {
      display: flex;
      flex-direction: column;
      padding: 0 20px;

      .menu-item {
        width: 100%;
        padding: 12px 0;
        border: none;
        background: transparent;
        cursor: pointer;
        text-align: center;
        border-radius: 4px;
        margin-bottom: 12px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        font-size: 20px;
        color: #333333;

        &.active {
          background: #327dff !important;
          color: #fff;
        }

        &:hover {
          background: #eef4ff;
        }
      }
    }
  }

  .main-content {
    flex: 1;
    box-sizing: border-box;
  }
}
</style>